package com.im.service.service;

import com.im.service.infra.entity.ChatHistory;
import com.im.service.infra.repository.ChatHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
@RequiredArgsConstructor
public class ChatHistoryService {
    private final ChatHistoryRepository chatHistoryRepository;

    public Mono<ChatHistory> saveChatHistory(ChatHistory chatHistory) {
        return chatHistoryRepository.save(chatHistory);
    }

    public Flux<ChatHistory> queryOfflineMessageByReceiverId(String userId) {
        return chatHistoryRepository.findChatHistoriesByReceiverIdAndForwardSuccessTimeIsNull(userId);
    }
}
